const fs = require('fs')
const utils = fs.readFileSync('./core/utils/utils.js').toString()
const loadImg = fs.readFileSync('./core/utils/load-img.js').toString()
const canvas = fs.readFileSync('./core/canvas.js').toString()
const layout = fs.readFileSync('./core/layout-tree.js').toString()
const render = fs.readFileSync('./core/render-tree.js').toString()
const main = fs.readFileSync('./core/main.js').toString()

const _element = fs.readFileSync('./core/element/_element.js').toString()
const button = fs.readFileSync('./core/element/button-element.js').toString()
const div = fs.readFileSync('./core/element/div-element.js').toString()
const image = fs.readFileSync('./core/element/image-element.js').toString()
const text = fs.readFileSync('./core/element/text-element.js').toString()
const tree = fs.readFileSync('./core/element/tree-element.js').toString()
const video = fs.readFileSync('./core/element/video-element.js').toString()
const star = fs.readFileSync('./core/element/star-element.js').toString()

try {
  fs.unlinkSync('./dist/main.js')
} catch (error) {}
const telempt =
  `
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = global || self, global.layout = factory());
  }(this, (function () {` +
  `${utils + loadImg}` +
  `${_element + button + div + image + text + tree + video + star}` +
  `${canvas + render + layout}` +
  `${main}` +
  `return layout
})));
`
fs.writeFileSync('./dist/main.js', telempt)
